<template>
  <div>
    <el-upload class="upload-demo" :action="uploadUrl" :on-preview="handlePreview"
      :before-upload="beforeUpload" :show-file-list="false" name="files" :disabled="disabled!==''"
      :on-error="error" :on-success="success">
      <slot></slot>
    </el-upload>
  </div>
</template>

<script>
import { importStudent } from "@/api/user";
export default {
  props: {
    fileType: {
      type: String,
      default: "xls"
    },
    disabled: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      uploadUrl: this.$Url + '/upload/fileUpload',
      uploadHander: {
        // 'Accept': 'multipart/form-data',
      },
      typeTab: {
        xls: 'application/vnd.ms-excel',
        xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      },
      fileList: []
    };
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
      this.fileList = fileList;
    },
    handlePreview(file) {
      console.log(file);
    },
    beforeUpload(file) {
      if (file.size > 10 * 1024 * 1024) {
        this.$message.error("文件大小超过10M！");
        return false;
      } else {
        if (this.typeTab[this.fileType] !== file.type) {
          this.$message.error("请上传" + this.fileType + "格式文件！");
          return false
        }
      }
    },
    success(response) {
      this.$emit("uploadUrl", response.data);
    },
    error(error) {
      this.$message.error(error.type);
    }
  }
};
</script>
<style lang="scss" scoped></style>
